package com.jg.xmlSchema2JsonSchema.xsd;

import com.jg.xmlSchema2JsonSchema.xsd.util.XsdUtil;
import org.w3c.dom.Element;

import java.util.List;

public class XsExtension {

    private Element element;
    private String annotation;
    private String base;
    private String id;

    public XsExtension(Element element) {
        this.element = element;
        getData();
    }

    private void getData() {
        XsAnnotation xsAnnotation = XsdUtil.getAnnotation(element);
        if (xsAnnotation != null) {
            annotation = xsAnnotation.getText();
        }
        id = element.getAttribute("id");
        base = element.getAttribute("base");
    }

    public String getAnnotation() {
        return annotation;
    }

    public String getBase() {
        return base;
    }

    public String getId() {
        return id;
    }

    public List<XsAttribute> getAttributes() {
        return XsdUtil.getAttributes(element);
    }

    public XsAttribute getAttribute(String name) {
        List<XsAttribute> attributes = XsdUtil.getAttributes(element);
        for (XsAttribute xa : attributes) {
            if (xa.getName().equals(name)) {
                return xa;
            }
        }
        return null;
    }

    public XsSequence getSequence() {
        return XsdUtil.getSequence(element);
    }

    public Element getXmlElement() {
        return element;
    }
}
